package com.ruoyi.web.controller;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCourseStudyRecord;
import com.ruoyi.system.service.ISysCourseStudyRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学习记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@Controller
@RequestMapping("/system/sysCourseStudyRecord")
public class SysCourseStudyRecordController extends BaseController
{
    private String prefix = "system/sysCourseStudyRecord";

    @Autowired
    private ISysCourseStudyRecordService sysCourseStudyRecordService;

    @RequiresPermissions("system:sysCourseStudyRecord:view")
    @GetMapping()
    public String sysCourseStudyRecord()
    {
        return prefix + "/sysCourseStudyRecord";
    }

    @RequiresPermissions("system:sysCourseStudyRecord:student:view")
    @GetMapping(value = "student")
    public String sysCourseStudyRecordStudent()
    {
        return prefix + "/sysCourseStudyRecordStudent";
    }

    /**
     * 查询学习记录列表
     */
    @RequiresPermissions("system:sysCourseStudyRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCourseStudyRecord sysCourseStudyRecord)
    {
        startPage();
        List<SysCourseStudyRecord> list = sysCourseStudyRecordService.selectSysCourseStudyRecordList(sysCourseStudyRecord);
        return getDataTable(list);
    }

    /**
     * 查询学习记录列表
     */
    @RequiresPermissions("system:sysCourseStudyRecord:student:list")
    @PostMapping("/studentList")
    @ResponseBody
    public TableDataInfo listStudent(SysCourseStudyRecord sysCourseStudyRecord)
    {
        startPage();
        sysCourseStudyRecord.setUserId(ShiroUtils.getUserId());
        List<SysCourseStudyRecord> list = sysCourseStudyRecordService.selectSysCourseStudyRecordList(sysCourseStudyRecord);
        return getDataTable(list);
    }

    /**
     * 导出学习记录列表
     */
    @RequiresPermissions("system:sysCourseStudyRecord:export")
    @Log(title = "学习记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysCourseStudyRecord sysCourseStudyRecord)
    {
        List<SysCourseStudyRecord> list = sysCourseStudyRecordService.selectSysCourseStudyRecordList(sysCourseStudyRecord);
        ExcelUtil<SysCourseStudyRecord> util = new ExcelUtil<SysCourseStudyRecord>(SysCourseStudyRecord.class);
        return util.exportExcel(list, "学习记录数据");
    }

    /**
     * 新增学习记录
     */
    @RequiresPermissions("system:sysCourseStudyRecord:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学习记录
     */
    @RequiresPermissions("system:sysCourseStudyRecord:add")
    @Log(title = "学习记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysCourseStudyRecord sysCourseStudyRecord)
    {
        return toAjax(sysCourseStudyRecordService.insertSysCourseStudyRecord(sysCourseStudyRecord));
    }

    /**
     * 修改学习记录
     */
    @RequiresPermissions("system:sysCourseStudyRecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysCourseStudyRecord sysCourseStudyRecord = sysCourseStudyRecordService.selectSysCourseStudyRecordById(id);
        mmap.put("sysCourseStudyRecord", sysCourseStudyRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存学习记录
     */
    @RequiresPermissions("system:sysCourseStudyRecord:edit")
    @Log(title = "学习记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysCourseStudyRecord sysCourseStudyRecord)
    {
        return toAjax(sysCourseStudyRecordService.updateSysCourseStudyRecord(sysCourseStudyRecord));
    }

    /**
     * 删除学习记录
     */
    @RequiresPermissions("system:sysCourseStudyRecord:remove")
    @Log(title = "学习记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysCourseStudyRecordService.deleteSysCourseStudyRecordByIds(ids));
    }
}
